package lab5task3;

/**
 * 
 * Connection class of database connection pool implementation
 * 
 * @author Bulaev Igor
 *
 */

public class Connection {
	
	private Thread owner;
	private long idleTime;
	
	public void setOwner(Thread owner) {
		this.owner = owner;
	}
	
	public Thread getOwner() {
		return owner;
	}
	
	public long getIdleTime() {
		return idleTime;
	}
	
	/**
	 * 
	 * Method that simulates work in connection. Idle time
	 *  counter restarts after each invocation
	 * 
	 * @throws ConnectionClosedException - if connection already closed
	 */
	
	public void simulateWork() throws ConnectionClosedException {
		if(owner != null && owner == Thread.currentThread()) {
			idleTime = System.currentTimeMillis();
		} else {
			throw new ConnectionClosedException();
		}
	}
	
}
